# this dither matrix also comes from https://people.ece.ubc.ca/irenek/techpaps/introip/manual04.html
dm45c: list = [
	[167, 200, 230, 216, 181],
	[94,  72,  193, 242, 232],
	[36,  52,  222, 167, 200],
	[181, 126, 210, 94,  72],
	[232, 153, 111, 36,  52]
]

def dither(img: list):
	"""
	:param img: the greyscale image array
	:return: halftone image through dither
	"""
	# prepare the generated img
	out_img: list = []

	# move dither matrix to compare pixsel
	for (i, row) in enumerate(img):
		row_dither: list = []
		for (j, pix) in enumerate(row):
			if pix > dm45c[i % 5][j % 5]:
				row_dither.append(255)
			else:
				row_dither.append(0)
		out_img.append(row_dither)
	
	# output processed image
	return out_img
